<?php

namespace app\admin\model;

use think\Model;

class Expense extends Model
{
    // 表名
    protected $name = 'expense';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'type_text',
        'user_id_text',
        'admin_id_text'
    ];
    

    
    public function getTypeList()
    {
        return ['0' => __('Type 0'),'1' => __('Type 1')];
    }     


    public function getTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['type'];
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getUserList(){
        $model = model('user');
        $data = $model->getUserList();
        return $data;
    }

    public function getAdminList(){
        $adminM = new Admin();
        $data = $adminM->getList();
        return $data;
    }

    public function getAdminIdTextAttr($value, $data)
    {
        $value = $value ? $value : $data['admin_id'];
        $list = $this->getAdminList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getUserIdTextAttr($value, $data)
    {
        $value = $value ? $value : $data['user_id'];
        $list = $this->getUserList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
